home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Hardware / PCI Driver Development Kit / • Samples / Open Firmware Samples / Display sample / AAPL-VIPER.of next >
Encoding:
Text File  |  1996-08-20  |  10.0 KB  |  365 lines  |  [TEXT/MPS ]

  1. \ ***************************************************************
  2. \ * Sample FCode driver for a "display" card.
  3. \ *
  4. \ * Note that this version supports the Multi-color Terminal
  5. \ * Emulator extension, as implemented in the A7 (and, beyond) ROM.
  6. \ * The exact behavior of the Terminal Emulator may change.
  7. \ *
  8. \ * In particular, the new version will set FOREGROUND-COLOR
  9. \ * and BACKGROUND-COLOR to 0 and 15 if it detects our
  10. \ * "ISO6429-1983-COLORS" property.  This version of the driver
  11. \ * initializes the CLUT based upon whether it detects the presence
  12. \ * of an implementation of FOREGROUND-COLOR.  If not, it will
  13. \ * initialize so that the standard 1275 Terminal Emulator works.
  14. \ ***************************************************************
  15.  
  16. \ ***************************************************************
  17. \ *  NOTE:  The following PCI-HEADER arguments are correct for this
  18. \ * card.  They MUST correspond to your devices Device-ID, Vendor-ID
  19. \ * and CLASS-CODE.
  20. \ ***************************************************************
  21. tokenizer[ hex 100E 9001 030000 decimal ]tokenizer PCI-HEADER
  22.  
  23. FCODE-VERSION2
  24.  
  25. HEADERLESS
  26. 0 value MEM-SPACE-SIZE    \ size of 
  27. 0 value FRAME-BFR-PHYS    \ frame buffer physical address
  28. 0 value VIPER#            \ config #
  29. 0 value IO-SPACE-SIZE    \ from 2nd config
  30. 0 value IO-SPACE-PHYS    \ from "assigned addresses"instance
  31. 0 value IO-BASE            \ for I/O cycle generationinstance
  32. 0 value REG-BASE        \ for 9000 register accesses
  33. 0 value FRAME-BFR-VIRT    \ frame buffer virtual address
  34.  
  35. : >Command    h# 04 + ;
  36. : >Base0    h# 10 + ;
  37. : >Base1    h# 14 + ;
  38. : config-b@    " config-b@"    $call-parent ;
  39. : config-b!    " config-b!"    $call-parent ;
  40. : config-w@    " config-w@"    $call-parent ;
  41. : config-w!    " config-w!"    $call-parent ;
  42. : config-l@    " config-l@"    $call-parent ;
  43. : config-l!    " config-l!"    $call-parent ;
  44. : command-set    VIPER# >Command tuck config-w@ or  swap config-w! ;
  45. : command-clr    invert VIPER# >Command tuck config-w@ and swap config-w! ;
  46. : io-b@        io-base + rb@ ;
  47. : io-b!        io-base + rb! ;
  48. : io-w@        io-base + rw@ ;
  49. : io-w!        io-base + rw! ;
  50. : reg-l@    reg-base + rl@ ;
  51. : reg-l!    reg-base + rl! ;
  52. : map-in    " map-in"    $call-parent ;
  53. : map-out    " map-out"    $call-parent ;
  54. : ENCODE-PCI-REG
  55.     >r >r VIPER# or encode-int rot encode-int encode+ rot encode-int encode+
  56.     r> r> encode-int rot encode-int encode+ encode+
  57.     ;
  58.  
  59. hex
  60. \ following are offset to Memory addresses
  61. 004 constant kdSysConfig
  62. 008 constant kdInterrupt
  63. 00C constant kdInterruptEnable
  64. 104 constant kdHorzCounter
  65. 108 constant kdHorzLength
  66. 10C constant kdHorzSyncRisingEdge
  67. 110 constant kdHorzBlankRisingEdge
  68. 114 constant kdHorzBlankFallingEdge
  69. 118 constant kdHorzCounterPreload
  70. 11C constant kdVertCounter
  71. 120 constant kdVertLength
  72. 124 constant kdVertSyncRisingEdge
  73. 128 constant kdVertBlankRisingEdge
  74. 12C constant kdVertBlankFallingEdge
  75. 130 constant kdVertCounterPreload
  76. 134 constant kdScreenRepaintAddress
  77. 138 constant kdScreenRepaintTiming
  78. 13C constant kdScreenRefreshTiming
  79. 184 constant kdMemConfig
  80. 188 constant kdRefreshPeriod
  81. 190 constant kdRasMax
  82.  
  83. \ following addresses are I/O addresses
  84. 8402 constant kBT485Reg0
  85. 8800 constant kBT485Reg1
  86. 8801 constant kBT485Reg2
  87. 8802 constant kBT485Reg3
  88. 03C6 constant kPixelMask
  89. 03C7 constant kRamRead
  90. 03C8 constant kRamWrite
  91. 03C9 constant kRamData
  92. decimal
  93.  
  94.     my-space to VIPER#
  95.     -1 VIPER# >base0 config-l!
  96.     VIPER# >base0 config-l@  h# FFFFFFF0 and negate to mem-space-size
  97.     0 VIPER# >base0 config-l!
  98.     h# 10000 to io-space-size
  99.     h# 8000 VIPER# >base1 config-l!
  100.     " AAPL,Viper" device-name
  101.     0 0 0  0 0
  102.       encode-pci-reg
  103.     0 0 h# 02000010   mem-space-size 0
  104.       encode-pci-reg  encode+
  105.     0 0 h# 81000000   io-space-size 0
  106.       encode-pci-reg  encode+
  107.         " reg" property
  108.     " display" device-type
  109.     " viper" model
  110.  
  111.     640 encode-int    " width" property
  112.     480 encode-int    " height" property
  113.     8 encode-int    " depth" property
  114.     640 encode-int    " linebytes" property
  115.     0 0                " iso6429-1983-colors" property        \ we support extensions
  116.  
  117. 0 value clkx
  118. : clk!    ( data clk )
  119.     2 << swap 3 << or clkx or h# 3C2 io-b!
  120.     ;
  121.  
  122. : setupClock    ( _vclk )
  123.     h# 3CC io-b@ h# F3 and to clkx    \ get "whatever"
  124.  
  125. \ unlock the clock chip
  126.     1 1 clk!
  127.     5 0 do
  128.         1 0 clk!
  129.         1 1 clk!
  130.         loop
  131.     1 0 clk!
  132.     0 0 clk!
  133.     0 1 clk!
  134.  
  135. \ start bits
  136.     0 0 clk!
  137.     0 1 clk!
  138.  
  139. \ Manchester encode the value
  140.     24 0 do                                            ( vclk )
  141.         dup 1 xor 1 and dup 1 clk! 0 clk!            ( vclk )
  142.         dup       1 and dup 0 clk! 1 clk!            ( vclk )
  143.         1 >>                                        ( vclk )
  144.         loop
  145.     drop                                            ( -- )
  146.  
  147. \ stop bits
  148.     1 1 clk!
  149.     1 0 clk!
  150.     1 1 clk!
  151.     ;
  152.  
  153. : setupDAC    ( _vclk _depth )
  154.     h# 82    kBT485Reg0    io-b!
  155.     h# 30    kBT485Reg2    io-b!
  156.     h# 01    kRamWrite    io-b!
  157.     over h# 20 and if h# 08 else h# 00 then  kBT485Reg3 io-b!    ( vclk depth )
  158.     dup case                                                    ( vclk depth depth )
  159.          8 of
  160.              h# 40
  161.             endof
  162.         16 of
  163.             h# 30
  164.                endof
  165.         24 of
  166.             h# 10
  167.                endof
  168.         32 of
  169.             h# 10
  170.                endof
  171.            endcase                                                    ( vclk depth val )
  172.             kBT485Reg1    io-b!                                    ( vclk depth )
  173.     h# FF    kPixelmask    io-b!                                    ( vclk depth )
  174.     h# 12    h# 03C4 io-b!                                        ( vclk depth )
  175.     h# 03C5 io-b@ h# 10 or h# 03C5 io-b!                        ( vclk depth )
  176.  
  177.     swap 8 >> setupClock                                        ( depth )
  178.  
  179.     h# 0C h# 03C2 io-b!                                            ( depth )
  180.     8 = if                                                        ( -- )
  181.         0 kRamWrite io-b!
  182.         h# 100 0 do                \ initialize to smooth grey
  183.             h# FF i -
  184.             dup kRamData io-b!    \ red
  185.             dup kRamData io-b!    \ green
  186.                 kRamData io-b!    \ blue
  187.             loop
  188.       then
  189.     ;
  190.  
  191. : VIPERinit
  192.     0 to FRAME-BFR-PHYS
  193.     " assigned-addresses" get-my-property abort" no assigned-addresses"
  194.     begin                                    \ search for my FRAME-BFR base
  195.         dup while
  196.         decode-phys h# FF and h# 10 = if    \ this is for BASE0
  197.             drop to FRAME-BFR-PHYS
  198.           else
  199.             2drop
  200.           then
  201.         decode-int drop decode-int drop        \ size values
  202.         repeat
  203.     2drop                                    \ drop final prop.adr prop.len pair
  204.  
  205.     FRAME-BFR-PHYS h# 100000 + 0 h# 02000000 VIPER# or
  206.         h# 200 map-in to reg-base            \ get addressability to my regs
  207.  
  208.     0 0 h# 81000000 VIPER# or
  209.         io-space-size map-in to io-base        \ and, dumb old I/O space
  210.  
  211.     3 command-set                            \ enable both RAM and I/O cycles
  212.  
  213.     h# 00000080 kdInterruptEnable    reg-l!
  214.     h# 00000186 kdRefreshPeriod        reg-l!
  215.     h# 000000FA kdRasMax            reg-l!
  216.  
  217.     h# 45A8BCD0    8 setupDAC                    \ clock
  218.  
  219.     h# 00000002 kdMemConfig            reg-l!
  220.     h# 00563000 kdSysConfig            reg-l!
  221.      23 kdHorzSyncRisingEdge        reg-l!
  222.      33 kdHorzBlankRisingEdge        reg-l!
  223.     193 kdHorzBlankFallingEdge        reg-l!
  224.     199 kdHorzLength                reg-l!
  225.       0 kdHorzCounterPreload        reg-l!
  226.  
  227.       1 kdVertSyncRisingEdge        reg-l!
  228.      25 kdVertBlankRisingEdge        reg-l!
  229.     505 kdVertBlankFallingEdge        reg-l!
  230.     525 kdVertLength                reg-l!
  231.       0 kdVertCounterPreload        reg-l!
  232.  
  233.  h# 1E5    kdScreenRepaintTiming        reg-l!
  234.  
  235.     reg-base h# 200 map-out                        \ don't need regs anymore
  236.     io-base io-space-size map-out                \  nor, I/O
  237.     1 command-clr                                \ disable I/O for shared environment
  238.     FRAME-BFR-PHYS h# 00200000 + 0 h# 02000000 VIPER# or
  239.         h# 00200000 map-in to FRAME-BFR-VIRT    \ get addressability to frame buffer
  240.     ;
  241.  
  242. decimal
  243.  
  244. variable RGB-temp    \ used for COLOR! & COLOR@
  245. : map-in-io
  246.     0 0 h# 81000000 VIPER# or io-space-size map-in to io-base
  247.     1 command-set                        \ enable I/O accesses
  248.     ;
  249. : map-out-io
  250.     1 command-clr                        \ disable I/O
  251.     io-base io-space-size map-out
  252.     ;
  253. : rect-setup    ( adr|index x y w h -- w adr|index xy-adr h )
  254.     >r >r 640 * + frame-buffer-adr + r> -rot r>
  255.     ;
  256. EXTERNAL
  257.  
  258. \ ******* the following are new routines added by the Terminal Emulator Extensions
  259. : SET-COLORS    ( adr index #indices -- )
  260.     map-in-io
  261.     swap kRamWrite io-b!                \ initialize index
  262.     ( #indices ) 0 ?do                ( adr )
  263.         dup c@  kRamData io-b! 1+    ( adr )        \ R
  264.         dup c@  kRamData io-b! 1+    ( adr )        \ G
  265.         dup c@  kRamData io-b! 1+    ( adr )        \ B
  266.         loop                        ( adr )
  267.     drop
  268.     map-out-io
  269.     ;
  270. : GET-COLORS    ( adr index #indices -- )
  271.     map-in-io
  272.     swap kRamRead io-b!                    \ initialize index
  273.     ( #indices ) 0 ?do                ( adr )
  274.         kRamData io-b@ over c! 1+    ( adr )        \ R
  275.         kRamData io-b@ over c! 1+    ( adr )        \ G
  276.         kRamData io-b@ over c! 1+    ( adr )        \ B
  277.         loop                        ( adr )
  278.     drop
  279.     map-out-io
  280.     ;
  281. : COLOR!        ( r g b index -- )
  282.     >r RGB-temp 2+ tuck c! 1- tuck c! 1- c!        \ setup our packed buffer
  283.     RGB-temp r> 1 set-colors                    \  and, use our own code
  284.     ;
  285. : COLOR@        ( index -- r g b )
  286.     RGB-temp swap 1 get-colors                    \ fetch one set
  287.     RGB-temp dup c@ swap 1+ dup c@ swap 1+ c@    \ split them out
  288.     ;
  289.  
  290. : DRAW-RECTANGLE    ( adr x y w h -- )
  291.     rect-setup                                 ( w adr xy-adr h )
  292.     ( h ) 0 ?do                                ( w adr xy-adr )
  293.         2dup 4 pick move
  294.         2 pick 640 d+
  295.         loop
  296.     3drop
  297.     ;
  298. : FILL-RECTANGLE    ( index x y w h -- )
  299.     rect-setup >r swap r>                    ( w index xy-adr h )
  300.     ( h ) 0 ?do                                ( w index xy-adr )
  301.         dup 3 pick 3 pick fill
  302.         640 +
  303.         loop
  304.     3drop
  305.     ;
  306. : READ-RECTANGLE    ( adr x y w h -- )
  307.     rect-setup >r swap r>                    ( w xy-adr adr h )
  308.     ( h ) 0 ?do
  309.         2dup 4 pick move
  310.         640 3 pick d+
  311.         loop
  312.     3drop
  313.     ;
  314.  
  315. \ ***************************************************************
  316. \ Note that MY-OPEN does not return the flag associated with
  317. \ the OPEN call.  The shell code generated by Open Firmware for
  318. \ the IS-INSTALL word generates the result value.
  319. \ ***************************************************************
  320.  
  321. : my-open
  322.     VIPERinit
  323. \ **********************************************************************
  324. \ * Note:  the CLUT setup is being done depending upon the presence of
  325. \ * the FOREGROUND-COLOR FCode (which is new for 16-Color Extension).
  326. \ **********************************************************************
  327.  
  328. \ ** detect if Terminal Emulator can support 16-colors
  329.     h# 168 get-token drop  ['] ferror  <> if
  330.  
  331.         \ *** 16-color is supported by Terminal Emulator, so setup CLUT
  332.         \        black    red  green  brown   blue  magenta cyan  white
  333.             " "(000000 AA0000 00AA00 AA5500 0000AA AA00AA 00AAAA AAAAAA)" drop
  334.                 0 8 set-colors
  335.         \        grey     red  green  yellow  blue  magenta cyan  white
  336.             " "(AAAAAA FF0000 00FF00 FFFF00 0000FF FF00FF 00FFFF FFFFFF)" drop
  337.                 8 8 set-colors
  338.         15        \ leave WHITE background fill for clear routine
  339.  
  340.       else    \ ** 16-color support not present, setup for standard 1275
  341.  
  342.          0  0  0    0        color!        \ initialize BACKGROUND color
  343.         -1 -1 -1    h# FF    color!        \ initialize FOREGROUND color
  344.         0        \ leave WHITE background for clear
  345.  
  346.       then
  347.  
  348.  
  349.     ( background ) FRAME-BFR-VIRT h# 00200000 rot fill        \ clear the buffer
  350.  
  351.     default-font set-font
  352.     640 480 100 40 fb8-install
  353.     FRAME-BFR-VIRT to frame-buffer-adr
  354.     ;
  355. ['] my-open is-install
  356.  
  357. : my-close
  358.     FRAME-BFR-VIRT h# 00200000 map-out
  359.     ;
  360. ['] my-close is-remove
  361.  
  362. FCODE-END
  363.  
  364. PCI-END
  365.